<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$img = M('img')->limit('5')->select();
    	$this -> assign('img',$img);
    	$news = M('news')->limit('3')->select();
    	$this -> assign('news',$news);
    	$fenlei = M('fenlei')->select();
    	$this -> assign('fenlei',$fenlei);
    	$linian = M('linian')->limit('3')->select();
    	$this -> assign('linian',$linian);
    	$product = M('product')->limit('5')->select();
    	$this -> assign('product',$product);
        $this -> display();

    }
    public function news(){
    	$info = M('news')->select();
    	if($info){
	    	foreach($info as $k => $v){
                $time = date('Y-m-d H:i:s',time());
	    		$info[$k]['year'] = substr($time,0,4);
	    		$info[$k]['m'] = substr($time,4,2);
                  if($info[$k]['m']>9){
                    $info[$k]['m'];
                }else{
                     $info[$k]['m'] = substr( $info[$k]['m'],1);
                }
	    		$info[$k]['d'] = substr($time,6,2);
                  if($info[$k]['d']>9){
                    $info[$k]['d'];
                }else{
                     $info[$k]['d'] = substr( $info[$k]['d'],0,1);
                }

	    	}
    	}
    	$this -> assign('info',$info);
    	$this ->display();
    }
    public function service(){
       $info =  M('question')->select();
       $i=1;
       foreach ($info as $key => $value) {
           $info[$key]['sorce'] = $i;
        $i++;
       }
       $this -> assign('info',$info);
    	$this ->display();
    }
    public function about_us(){
    	$this ->display();
    }
    public function products_and_solution(){
        //分类
    	$fenlei = M('fenlei')->order('id asc')->select();
        $this -> assign('fenlei',$fenlei);
        //图片
        $start = M('fenlei')->order('id asc')-> limit(1)->find();
        $product = M('product')->where(array('pid'=>$start['id']))->select();
        $this -> assign('product',$product);
    	$this -> display();
    }
    public function qiehuan(){
         //分类
        $fenlei = M('fenlei')->order('id asc')->select();
        $this -> assign('fenlei',$fenlei);
        $id=I('get.id');
       // echo  $id;die;
         $product = M('product')->where(array('pid'=>$id))->select();
        $this -> assign('product',$product);
        $this -> display('products_and_solution');
    }
    public function pro_details(){
        $id = I('get.id');
        $info = M('product')->where(array('id'=>$id))->find();
         $this -> assign('info',$info);
        $this -> display();
    }
    public function news_details(){
        $info = M('news')->where(array('id'=>I('get.id')))->find();
        $info['time'] = date('Y-m-d H:i:s',time());
        $this -> assign('info',$info);
        $this -> display();
    }
}